#include <REGX52.H>
#include "Timer1.h"

sbit Motor = P1^0;//直流电机


//unsigned char KeyNum_f,Speed = 0;
unsigned char Counter,Compare;//前者计数，后者作为比较变量

void Motor_Init()
{
	Timer1_Init();
}

void Motor_SetSpeed(unsigned char Speed)
{ 
	Compare = Speed;
}

void Timer1_Routine() interrupt 3  //定时器0的中断函数
{
	
	TL1 = 0x66;		//设置定时初值
	TH1 = 0xFC;		//设置定时初值	
	Counter++;
	
	
	if(Counter >= 100) Counter = 0;
	if(Counter < Compare) {Motor = 1;}
	else {Motor = 0;}
}

